writable store
Posted on 2023-02-12 by
henrikvilhelmberglundSvelte has a few built-in store functions , one of them being the writable store .
We use them by importing them from "svelte/store" like this:
import { writable, readable } from "svelte/store";
writable is a store where we can both read and write , and readable is a store that is read only .
Both of these stores have a method called subscribe that allows you to subscribe to the store .
The writable store has a method called set that allows you to set (and update) the value .
value: undefined
<script>
import Input from "./Input.svelte";
import Output from "./Output.svelte";
</script>
<Input />
<Output />
As you can see we could remove a lot of code by using the built in writable store functionality.